<template>
	<view class="example">
		<uni-forms ref="baseForm" :modelValue="user">
			<uni-forms-item label="用户名" required>
				<uni-easyinput :value="user.username" v-model="user.username" placeholder="请输入新用户名" />
			</uni-forms-item>
			<uni-forms-item label="真实姓名" required>
				<uni-easyinput :value="user.truename" v-model="user.truename" placeholder="请输入新姓名" />
			</uni-forms-item>
			<picker @change="bindPickerChange" :value="sexType[user.sex]" :range="sexType">
				<view class="uni-input">{{sexType[user.sex]}}</view>
			</picker>
			<uni-forms-item label="职称" required>
				<uni-easyinput :value="user.rank" v-model="user.rank" placeholder="请输入职称" />
			</uni-forms-item>
			<uni-forms-item label="密码" required>
				<uni-easyinput :value="user.password" v-model="user.password" placeholder="请输入新密码" />
			</uni-forms-item>
			<uni-forms-item label="联系方式" required>
				<uni-easyinput :value="user.contact" v-model="user.contact" placeholder="请输入新联系方式" />
			</uni-forms-item>
		</uni-forms>
		
		<button type="primary" plain="true" @click="confirm">确认</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				sexType: ['女', '男'],
				campus: [{
					text: '广州校区东校园',
					value: 0
				}, {
					text: '广州校园北校区',
					value: 1
				}, {
					text: '广州校区南校园',
					value: 2
				},{
					text: '深圳校区',
					value: 3
				},{
					text: '珠海校区',
					value: 4
				}],
			}
		},
		onLoad(options) {
			let data = JSON.parse(options.user);
			console.log(data.uid)
			this.user = data
		},
		methods: {
			submit(ref) {
				this.$refs[ref].validate().then(res => {
					console.log('success', res);
					uni.showToast({
						title: `校验通过`
					})
				}).catch(err => {
					console.log('err', err);
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.defaultWorker = e.detail.value
			},
			confirm() {
				//this.$eventHub.$emit('fire', this.user);
				this.$emit("getchange", this.user);
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style>
	.example {
		padding: 20px;
		background-color: #fff;
	}
	.button {
		width: 80%;
	}
</style>